


#ifndef PF_PAINTER_H
#define PF_PAINTER_H

#include "pf_color.h"
#include "pf_math.h"
#include "pf_pen.h"
#include "pf_vector.h"
#include <qpolygon.h>
#include "lx_Export.h"


/**
 * This class is a common interface for a painter class. Such 
 * a class will in it's implementation be responsible to paint
 * lines, arcs, ... in widgets. All angles in rad.
 *
 * Note that this is just an interface used as a slot to 
 * communicate with the LXCAD from a GUI level. This 
 * does not contain any Qt or platform specific code.
 */
class LX_EXPORT PF_Painter {
public:
    PF_Painter() {
        drawingMode = LX_Define::ModeFull;
        offset = PF_Vector(0.0,0.0);
    }
    virtual ~PF_Painter() {}

    /**
     * Sets the drawing mode.
     */
    void setDrawingMode(LX_Define::DrawingMode m) {
        drawingMode = m;
    }

    /**
     * @return Current drawing mode.
     */
    LX_Define::DrawingMode getDrawingMode() {
        return drawingMode;
    }

	virtual void moveTo(int x, int y) = 0;
	virtual void lineTo(int x, int y) = 0;
	
    virtual void drawGridPoint(const PF_Vector& p) = 0;
    virtual void drawPoint(const PF_Vector& p) = 0;
    virtual void drawLine(const PF_Vector& p1, const PF_Vector& p2) = 0;
    virtual void drawRect(const PF_Vector& p1, const PF_Vector& p2);
    virtual void drawArc(const PF_Vector& cp, double radius,
                         double a1, double a2,
                         const PF_Vector& p1, const PF_Vector& p2,
                         bool reversed) = 0;
    virtual void drawArc(const PF_Vector& cp, double radius,
                         double a1, double a2,
                         bool reversed) = 0;
    void createArc(QPolygon& pa,
                   const PF_Vector& cp, double radius,
                   double a1, double a2,
                   bool reversed);
    virtual void drawCircle(const PF_Vector& cp, double radius) = 0;
    virtual void drawEllipse(const PF_Vector& cp,
                             double radius1, double radius2,
                             double angle,
                             double angle1, double angle2,
                             bool reversed) = 0;
        virtual void drawImg(QImage& img, const PF_Vector& pos,
			double angle, const PF_Vector& factor,
			int sx, int sy, int sw, int sh) = 0;

    virtual void drawTextH(int x1, int y1, int x2, int y2,
                           const QString& text) = 0;
    virtual void drawTextV(int x1, int y1, int x2, int y2,
                           const QString& text) = 0;

    virtual void fillRect(int x1, int y1, int w, int h, const PF_Color& col) = 0;
	virtual void fillRect ( const QRectF & rectangle, const PF_Color & color ) = 0;
	virtual void fillRect ( const QRectF & rectangle, const QBrush & brush ) = 0;
	
    virtual void fillTriangle(const PF_Vector& p1,
                              const PF_Vector& p2,
                              const PF_Vector& p3) = 0;

	virtual void drawHandle(const PF_Vector& p, const PF_Color& c, int size=-1);

    virtual PF_Pen getPen() = 0;
    virtual void setPen(const PF_Pen& pen) = 0;
    virtual void setPen(const PF_Color& color) = 0;
    virtual void setPen(int r, int g, int b) = 0;
    virtual void disablePen() = 0;
	virtual void setBrush(const PF_Color& color) = 0;
	virtual void drawPolygon(const QPolygon& a) = 0;
	virtual void erase() = 0;
	virtual int getWidth() = 0;
	virtual int getHeight() = 0;

    virtual void setOffset(const PF_Vector& o) {
        offset = o;
    }

    virtual void setClipRect(int x, int y, int w, int h) = 0;
    virtual void resetClipping() = 0;
    int toScreenX(double x) {
        return PF_Math::round(offset.x + x);
    }
    int toScreenY(double y) {
        return PF_Math::round(offset.y + y);
    }

protected:
    /**
     * Current drawing mode.
     */
    LX_Define::DrawingMode drawingMode;
    /**
     * A fixed offset added to all entities drawn (useful for previews).
     */
    PF_Vector offset;
};

#endif
